package com.kcsj.service;
/**
 * @author 傅立贤
 * 29th Nov. 2020
 */
import com.kcsj.dao.AddressDao;
import com.kcsj.domain.Address;
import com.kcsj.domain.DelayedApplication;
import com.kcsj.domain.user.Notice;
import com.kcsj.util.Condition;
import com.kcsj.util.JdbcHelper;
import com.kcsj.util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class AddressService {
    private AddressDao addressDao = AddressDao.getInstance();
    private static AddressService addressService
            = new AddressService();

    public AddressService() {
    }
    public static AddressService getInstance(){
        return addressService;
    }

    public boolean add(Address address) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        boolean added = addressDao.add(address, conn);
        JdbcHelper.close(conn);
        return added;
    }
    public Collection<Address> findAllByCustomerId(Integer customer_id) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<Address> addresses =
                addressDao.findAllByCustomerId(customer_id, conn);
        JdbcHelper.close(conn);
        return addresses;
    }
    public boolean update(Address address) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        boolean updated = addressDao.update(address, conn);
        JdbcHelper.close(conn);
        return updated;
    }

    public boolean delete(Integer id) throws SQLException{
        Connection connection = JdbcHelper.getConn();
        boolean deleted = addressDao.delete(id, connection);
        JdbcHelper.close(connection);
        return deleted;
    }

}
